package com.ebupt.migu.music.commons.selfdom.demo.impl;

import com.ebupt.migu.globalpopup.entity.ConditionRelation;
import com.ebupt.migu.globalpopup.enums.ConditionEnum;
import com.ebupt.migu.music.commons.selfdom.demo.Network;
import com.ebupt.migu.music.commons.selfdom.demo.impl.identifier.AbstractIdentifierEnImpl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 *  网络环境子条件实现类
 *
 * @author wangzhu
 * @since 2021-12-31
 */
public class NetworkImpl extends AbstractIdentifierEnImpl implements Network {
    /**
     * wifi
     */
    private boolean wifi(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }
    /**
     * 5G
     */
    private boolean fiveG(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * 4G
     */
    private boolean fourG(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * 3G
     */
    private boolean threeG(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * 2G
     */
    private boolean twoG(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }


    /**
     * 更具不同的子条件判断返回判断结果（子条件第一版只支持or）
     */
    @Override
    public boolean getNetwork(Map data, List<ConditionRelation> conditionRelations) {
        LinkedHashMap<Boolean, Integer> booleanIntegerLinkedHashMap = new LinkedHashMap<>();
        // 排序
        super.sort(conditionRelations);
        for (ConditionRelation conditionRelation : conditionRelations) {
            boolean network = true;
            Object o = data.get(ConditionEnum.getKeyValue(conditionRelation.getPropertyCode(), conditionRelation.getConditionKey()));
            if (o==null||o.equals("")) {
                network = false;
                booleanIntegerLinkedHashMap.put(network,conditionRelation.getCConnector());
                break;
            }
            String value = o.toString();
            switch (conditionRelation.getConditionKey()) {
                case 1:
                    network = this.wifi(value, conditionRelation,conditionRelation.getConditionKey());
                    break;
                case 2:
                    network = this.fiveG(value, conditionRelation,conditionRelation.getConditionKey());
                    break;
                case 3:
                    network = this.fourG(value, conditionRelation,conditionRelation.getConditionKey());
                    break;
                case 4:
                    network = this.threeG(value, conditionRelation,conditionRelation.getConditionKey());
                    break;
                case 5:
                    network = this.twoG(value, conditionRelation,conditionRelation.getConditionKey());
                    break;
                default:
                    break;
            }
            booleanIntegerLinkedHashMap.put(network, conditionRelation.getCConnector());
        }
        return super.getRelation(booleanIntegerLinkedHashMap);
    }





}
